/*
 * @Author: heinan
 * @Date: 2020-07-16 11:33:19
 * @Last Modified by: heinan
 * @Last Modified time: 2023-07-31 19:25:25
 */
"use strict";

const { Service } = require("egg");
const { idCreator } = require("../utils");

class ViewService extends Service {
  async create({
    view_authority_text,
    view_name,
    view_icon,
    view_level,
    view_authority_pid,
  }) {
    const $data = {
      view_authority_text,
      view_name,
      view_authority_id: idCreator(),
      view_icon,
      view_level,
      view_authority_pid,
    };
    return await this.app.mysql.insert("view_authority", $data);
  }
  async update({
    id,
    view_authority_text,
    view_name,
    view_icon,
    view_level,
    view_authority_pid,
  }) {
    const $data = {
      view_authority_text,
      view_name,
      view_icon,
      view_level,
      view_authority_pid,
    };
    const $options = { where: { view_authority_id: id } };
    return await this.app.mysql.update("view_authority", $data, $options);
  }
  async show({ id }) {
    return await this.app.mysql.get("view_authority", {
      view_authority_id: id,
    });
  }
  async index() {
    return await this.app.mysql.select("view_authority", {
      orders: [["view_authority_text", "asc"]],
    });
  }
  async destroy({ id }) {
    return await this.app.mysql.delete("view_authority", {
      view_authority_id: id,
    });
  }
}

module.exports = ViewService;
